home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac: Not for Sale / Another.not.for.sale (Australia).iso / fade into you / getting there / WWW / MacHTTP Extras / Tokenize OSAX / Tokenize READ ME < prev    next >
Encoding:
Text File  |  1994-10-14  |  3.9 KB  |  80 lines  |  [ttro/ttxt]

  1.  
  2. _________________________________________________
  3.  
  4.     Tokenize Scripting Addition ver. 1.0 
  5.             Copyright (C) 1994 Wayne Walrath
  6.  
  7. _________________________________________________
  8.  
  9. Tokenize is free for personal use only. You are encouraged to redistribute it but this document must be included. Cheap licenses are available for site or commercial distribution. Contact me at one of the addresses below for details (electronic contact preferred). THE AUTHOR PROVIDES NO WARRANTIES FOR THIS SOFTWARE. USE AT YOUR OWN RISK!
  10.  
  11.  
  12. The demo AppleScript included with the distribution contains many examples of Tokenize's usage.
  13.  
  14. Tokenize was designed to make it easier to split text into elements based on a set of delimiters. The demo AppleScript illustrates several novel uses for Tokenize which may not be obvious at first glance.
  15.  
  16.  
  17. INSTALLATION:
  18. ______________________
  19. To install: Drag the Tokenize to the Scripting Additions folder inside the Extensions folder.
  20.  
  21.  
  22.  
  23. BACKGROUND INFORMATION
  24. ______________________
  25.  
  26. Because of the way the tokenization is implemented, Tokenize can also be used as a quick way of removing unwanted characters from a text string. To better understand what is possible with Tokenize, here's a brief description of how Tokenize functions. The text to be tokenized is scanned for each of the strings given in the delimiter list, and all occurrences of these strings are replaced by a special character (essentially a null-char). After all delimiters are processed, a final pass is made which gathers all the strings between the special characters into a list. Understanding this algorithm will help you to figuring out how text will ultimately be parsed when using Tokenize.
  27.  
  28.  
  29. For example, consider an arbitrary string of text which contains words separated by tab characters, and between each word there will be one to three tabs. Here's a string set up as described:
  30.  
  31.     set testString to "One\tGiant\t\tStep\tFor\t\t\tMankind"
  32.  
  33.  
  34. If I tokenize this string using tab as the only delimiter, It returns this list:
  35.  
  36.     tokenize testString with delimiters tab
  37. => {"One", "Giant", "Step", "For", "Mankind"}
  38.  
  39.  
  40. If, on the other hand, I tokenize using a string of three tabs, the output is different:
  41.  
  42.     tokenize testString with delimiters tab & tab & tab
  43. =>    {"One    Giant        Step    For", "Mankind"}
  44.  
  45.  
  46. The output from this version consists of a list of two strings. Since tokenize only found one place in the testString where there were three tab characters side by side it split the string there. Tokenizing with a two tab string would produce yet a different result.
  47.  
  48.  
  49.  
  50. USAGE:
  51. ______________________
  52.  
  53. tokenize <a String> with delimiters { [<sep. string 1>] [,<sep. string2]...}
  54.  
  55. the direct parameter to tokenize is a string, and the second (required) parameter is a list of strings (one or more bytes in length) to use in tokenizing the direct parameter.
  56.  
  57. If you are only tokenizing with one delimiter you need not pass it as a list since AppleScript will handle the coercion for you. For example, the following is legal:
  58.  
  59. tokenize "My Name Is" with delimiters " Name "
  60. =>    {"My","Is"}
  61.  
  62.  
  63. Some text processing tasks require more than one call to Tokenize to perform. As an example, if the variable myText contained a number of lines separated by return characters, and you wanted to retrieve the words from line five, you could write the following AppleScript commands:
  64.  
  65. tokenize myText with delimiters {return} tokenize (item 5 of result) with delimiters {space}
  66. =>    [result is a list with all the words from line five of the text]
  67.  
  68.  
  69. ______________________
  70. Comments, bug reports and suggestions are welcomed. Source code is available for $40, and I'll include the sources to any other OSAXen I may have written up to that point. If you have any ideas for useful Scripting Additions which haven't been written yet, send me a message describing your idea.
  71.  
  72.     ___________________________
  73.         Wayne Walrath
  74.         2010 Ravenswood Dr.
  75.         Evansville, IN 47714
  76.         (812) 476-8610
  77.         walrath@cs.indiana.edu
  78.         CIS: 70233,3151 
  79.     ___________________________
  80.